using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class Shop_Comment
	{
		private Conn conn;
		public Shop_Comment()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public Shop_Comment(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetAllAttributes()
		{
			string text = "SELECT  C.Id,C.UserName,P.ProductName,C.DateTime,C.[Level],C.State,C.[Content],C.ShopID,C.ProductIDFrom [HLShop_Comment] as C,[HLShop_Product] as P,[HLShop_Shop] as SWHERE S.ShopID=C.ShopID AND C.ShopID=P.ShopID AND C.ProductID=P.ProductID";
			text += " ORDER BY C.DateTime DESC";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetAttributesByShopID(int ShopID)
		{
			string text = "SELECT  C.Id,C.UserName,P.ProductName,C.DateTime,C.[Level],C.State,C.[Content],C.ShopID,C.ProductID  From [HLShop_Comment] as C,[HLShop_Product] as P,[HLShop_Shop] as S  WHERE S.ShopID=C.ShopID AND C.ShopID=P.ShopID AND C.ProductID=P.ProductID AND (C.ShopID= " + ShopID + ")";
			text += " ORDER BY C.DateTime DESC";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetAttributesByID(int Id)
		{
			string text = " SELECT  C.Id,C.UserName,P.ProductName,C.DateTime,C.[Level],C.State,C.[Content],C.ShopID,C.ProductID  From [HLShop_Comment] as C,[HLShop_Product] as P,[HLShop_Shop] as S  WHERE S.ShopID=C.ShopID AND C.ShopID=P.ShopID AND C.ProductID=P.ProductID AND (Id= " + Id + ")";
			text += " ORDER BY C.DateTime DESC";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetAttributesByProductID(int ProductID)
		{
			string text = "SELECT  C.Id,C.UserName,P.ProductName,C.DateTime,C.[Level],C.State,C.[Content],C.ShopID,C.ProductID  From [HLShop_Comment] as C,[HLShop_Product] as P,[HLShop_Shop] as S  WHERE S.ShopID=C.ShopID AND C.ShopID=P.ShopID AND C.ProductID=P.ProductID AND (C.ProductID= " + ProductID + ")";
			text += " ORDER BY C.DateTime DESC";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetAttributesByWhere(int Level, string Content, int ShopID, int ProductID, int State)
		{
			string text = "SELECT  C.Id,C.UserName,P.ProductName,C.DateTime,C.State,C.[Content],C.ShopID,C.ProductID,[Level] FROM [HLShop_Comment] as C,[HLShop_Product] as P,[HLShop_Shop] as S  WHERE S.ShopID=C.ShopID AND C.ShopID=P.ShopID AND C.ProductID=P.ProductID ";
			if (Content != "")
			{
				text = text + " AND (Content LIKE '%" + Content + "%')  ";
			}
			if (Level != 0)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					" AND (Level= ",
					Level,
					") "
				});
			}
			if (ShopID != 0)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					" AND (C.ShopID= ",
					ShopID,
					") "
				});
			}
			if (ProductID != 0)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					" AND (C.ProductID= ",
					ProductID,
					") "
				});
			}
			if (State != 2)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					" AND (State= ",
					State,
					") "
				});
			}
			text += "ORDER BY DateTime DESC";
			return this.conn.GetDataTable(text);
		}
		public DataTable GetAttributesByLevel(string Level, string Content, int ShopID, int ProductID, int State)
		{
			string text = "SELECT  C.Id,C.UserName,P.ProductName,C.DateTime,C.State,C.[Content],C.ShopID,C.ProductID,[Level] FROM [HLShop_Comment] as C,[HLShop_Product] as P,[HLShop_Shop] as S  WHERE S.ShopID=C.ShopID AND C.ShopID=P.ShopID AND C.ProductID=P.ProductID ";
			if (Content != "")
			{
				text = text + " AND (Content LIKE '%" + Content + "%')  ";
			}
			if (Level != "")
			{
				text = text + " AND (Level in (" + Level + ")) ";
			}
			if (ShopID != 0)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					" AND (C.ShopID= ",
					ShopID,
					") "
				});
			}
			if (ProductID != 0)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					" AND (C.ProductID= ",
					ProductID,
					") "
				});
			}
			if (State != 2)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					" AND (State= ",
					State,
					") "
				});
			}
			text += "ORDER BY C.DateTime DESC";
			return this.conn.GetDataTable(text);
		}
		public bool AddComment(int Level, string Content, string UserName, int ShopID, int ProductID, string OrderNum)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@Level", DbType.Int32, Level),
				this.conn.CreateParameter("@Content", DbType.String, Content),
				this.conn.CreateParameter("@UserName", DbType.String, UserName),
				this.conn.CreateParameter("@ShopID", DbType.Int32, ShopID),
				this.conn.CreateParameter("@ProductID", DbType.Int32, ProductID),
				this.conn.CreateParameter("@OrderNum", DbType.String, OrderNum)
			};
			return this.conn.Execute("INSERT INTO [HLShop_Comment] ([Level], [Content],[UserName],[ShopID],[ProductID],[OrderNum]) VALUES (@Level, @Content, @UserName, @ShopID,@ProductID,@OrderNum)", parameters) >= 1;
		}
		public bool DeleteComment(int Id)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@Id", DbType.Int32, Id);
			return this.conn.Execute("DELETE FROM [HLShop_Comment] WHERE (Id = @Id)", new IDbDataParameter[]
			{
				dbDataParameter
			}) > 0;
		}
		public bool UpdateComment(int State, int Id)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@State", DbType.Int32, State),
				this.conn.CreateParameter("@Id", DbType.Int32, Id)
			};
			return this.conn.Execute("UPDATE [HLShop_Comment] SET [State] = @State WHERE (([Id] = @Id))", parameters) >= 1;
		}
	}
}
